<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="门类" prop="categoryId">
        <!--  :disable-branch-nodes="true" -->
        <treeselect v-model="id" :options="deptOptions" clearable style="width: 240px"
          placeholder="请选择档案门类" noResultsText="暂无数据" :normalizer="normalizerCategoryID" @select="changeSelectTap" />
      </el-form-item>
      <el-form-item label="文件名" prop="fileName">
        <el-input v-model="queryParams.fileName" placeholder="请输入文件名" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="下载人员" prop="userName">
        <el-input v-model="queryParams.userName" placeholder="请输入下载人员" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table ref="table" v-loading="loading" :data="dataList" :height="tableHeight"
      @selection-change="handleSelectionChange">
      <el-table-column label="序号" type="index" :index="table_index" width="55" align="center" prop="id" />
      <el-table-column label="菜单" prop="menuName" align="center" />
      <el-table-column label="门类" prop="categoryName" align="center" />
      <el-table-column label="来源" prop="source" align="center" />
      <el-table-column label="文件名" prop="docName" align="center" />
      <el-table-column label="下载时间" prop="createTime" align="center" />
      <el-table-column label="下载次数" prop="frequency" align="center" />
      <el-table-column label="下载人员" prop="userName" align="center" />
     
      <!-- <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="primary" plain @click="handleDownload(scope.row)" v-hasPermi="['archive:down']">下载</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import estimateTableHeight from "@/mixins/estimateTableHeight";
import { selectDownloadRecord } from "@/api/archive/liyong/myDownloads";
import { listAllMenu } from "@/api/archive/archivesCategory";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listGROUPTree } from "@/api/archive/archivalAppraisal/bgqxIdentify/bgqxExamineApprove";
import { gettrees } from "@/api/archive/archiveTreeDefinition";
export default {
  name: "index",
  mixins: [estimateTableHeight], // 混入方法
  components: { Treeselect },
  data() {
    return {
      loading: true,
      dataList: [],
      total: 0,
      queryParams: {
        menuId: undefined,
        categoryId: undefined,
        fileName: undefined,
        userName: undefined,
        pageNum: 1,
        pageSize: 10
      },
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      applyOption: [],
      deptOptions: [],
      id:undefined
    }
  },
  created() {
    this.getDeptTree()
    this.getList()
  },
  methods: {
    // 只能选择数据下面有children 的数据，没有children的时候禁用
    normalizerCategoryID(node) {
      if (node.nodeType == 'fonds') {
        if (node.children == undefined || node.children == null || !node.children.length) {

          node['isDisabled'] = true;
        }

      }
      if (node.children == null || node.children == undefined || !node.children.length) {
        delete node.children;
      }
      return node
    },

    //触发档案门类下拉,根据门类ID获取当前门类下的全宗号lable
    changeSelectTap(val) {
      console.log(val)
      this.queryParams.categoryId = val.categoryId;
    },
    // 获取档案门类树
    getDeptTree() {
      gettrees().then(response => {
        this.deptOptions = response.data;
      })
    },
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    resetQuery() {
      this.id=undefined
      this.resetForm('queryForm')
      this.handleQuery()
    },
    getList() {
      selectDownloadRecord(this.queryParams).then(response => {
        this.dataList = response.rows
        for (let i = 0; i < response.rows.length; i++) {
          if (response.rows[i].borrowId == '-1') {
            this.dataList[i].source = '其他'
          } else {
            this.dataList[i].source = '借阅'
          }
        }
        this.total = response.total
        this.loading = false
      })
    },
    table_index(index) {
      return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleDownload(row) {
      this.form = {
        id: row.id,
        sydm: 'jyjl_xiazai'
      }
      this.download('/archive/downloadRecord/download', {
        ...this.form
      }, row.docName).then(() => {
        // 下载完成后调用
        this.getList();
      })
    }
  }
}
</script>

<style scoped></style>
